import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:qaun_ni_dev/provider/attributeProvide.dart';

class AttributeUpdate extends StatelessWidget {
  var attributeData;
  AttributeUpdate(this.attributeData);


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('更新属性'),
      ),
      body: Container(
        padding: EdgeInsets.all(15),
        child:ListView(
          children: <Widget>[
            _inputText(attributeData,context),
          ],
        ),
      ),
    );
  }

  Widget _inputText(attributeData, context){

  TextEditingController code = TextEditingController(text: attributeData.code);
  TextEditingController description = TextEditingController(text: attributeData.description);
  TextEditingController type = TextEditingController(text: attributeData.type);
  TextEditingController val = TextEditingController(text: attributeData.val);


    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(bottom: 15),
          padding: EdgeInsets.only(top: 2),
          child: TextField(
            controller: code,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '属性code',
              hintText: '请输入新code',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: description,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '描述',
              hintText: '请输入新的描述',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: type,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '属性类型',
              hintText: '请输入新的类型',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: val,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '属性键值',
              hintText: '请输入新的键值',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),

        RaisedButton(
          child: Text('提交更新'),
          onPressed: () {

            var formData = {
              'code': code.text,
              'id': attributeData.id,
              'type': type.text,
              'description': description.text,
              'val': val.text,
            };
            Provider.of<AttributeProvide>(context,listen: false).updateAttribute(context, formData);
          },
        )
      ],
    );
  }


}
